package com.agritech.command;

import java.util.Stack;

public class RemoteControl {
    private Command command;
    private Stack<Command> commandHistory = new Stack<>();

    public void setCommand(Command command) {
        this.command = command;
    }

    public void pressButton() {
        if (command != null) {
            System.out.println("遥控器: 按下按钮，执行命令...");
            command.execute();
            commandHistory.push(command); // 记录命令历史用于撤销
        } else {
            System.out.println("遥控器: 未设置命令。");
        }
    }

    public void pressUndoButton() {
        if (!commandHistory.isEmpty()) {
            Command lastCommand = commandHistory.pop();
            System.out.println("遥控器: 按下撤销按钮，撤销上一条命令...");
            lastCommand.undo();
        } else {
            System.out.println("遥控器: 命令历史为空，无法撤销。");
        }
    }
}